package com.digitalxpert.jargle.TestGui;
import java.text.ParseException;
import javax.swing.JFormattedTextField;
import javax.swing.text.DefaultFormatter;

/**
 * Class InnFormatter
 * 
 * @author Yerokhin Yuri copyright by Zsoft Company
 * @version 1.0
 */
public class NumberFormatter extends DefaultFormatter{
    private JFormattedTextField tf = null;
    public NumberFormatter(){
    }
    public void install(JFormattedTextField ftf){
        super.install(ftf);
        tf = ftf;
    }
    public Object stringToValue(String string) throws ParseException{
        try{
        	System.out.println("InnFormatter");
            if(string.length() > 0)
                Integer.parseInt(string);
            if(tf != null)
                tf.setValue(string);
            return string;
        }catch (Exception e){
        }
        Object value = tf.getValue();
        tf.setValue(value);
        return value;
    }
    public String valueToString(Object value) throws ParseException{
        if(value == null)
            return "";
        return value.toString();
    }
}
